{# Shared by pieces and pages #}

{% import 'apostrophe-ui:components/buttons.html' as buttons %}

{%- macro operations(operations) -%}
  <div data-batch class="apos-manage-batch-operations ">
    <div class="apos-field-input-select-wrapper apos-field-input-select-wrapper--small">
      <select name="batch-operation" class="apos-field-input apos-field-input--small apos-field-input-select apos-manage-batch-operations-select">
        {% for operation in operations %}
          <option value="{{ operation.name }}">
            {{ __ns('apostrophe', '%s Selected', operation.label) }} (0)
          </option>
        {% endfor %}
      </select>
    </div>
    {% if apos.utils.filterNonempty(operations, 'schema') %}
      <div class="apos-manage-batch-operation-forms">
    {% endif %}
    {% for operation in operations %}
      {% if operation.schema %}
        <div data-apos-batch-operation-form="{{ operation.name }}" class="apos-manage-batch-operation-form">
          {% for field in operation.schema %}
            {{ apos.schemas.field(field) }}
          {% endfor %}
        </div>
      {% endif %}
    {% endfor %}
    {% if apos.utils.filterNonempty(operations, 'schema') %}
      </div>
    {% endif %}
    <div class="apos-manage-batch-operations-buttons">
      {% for operation in operations %}
        {{ buttons.danger(__ns('apostrophe', 'Batch %s', operation.buttonLabel or operation.label), { action: 'batch-operation', value: operation.name }) }}
      {% endfor %}
    </div>
  </div>
{%- endmacro -%}
